package com.hp.bon.sgw.domain;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "T_AVP_MAP_INFO")
public class ConvMapInfo {
	public static final int AVP_INT32 = 1;
	public static final int AVP_INT64 = 2;
	public static final int AVP_U32 = 3;
	public static final int AVP_U64 = 4;
	public static final int AVP_F32 = 5;
	public static final int AVP_F64 = 6;
	public static final int AVP_UTF8String = 7;
	public static final int AVP_OctetString = 8;
	public static final int AVP_Grouped = 9;
	public static final int AVP_Address = 10;
	public static final int AVP_Time = 11;
	public static final int AVP_Enumerated = 12;
	private int id;
	private String serviceCtxID;
	private int venderID = 81000;
	private int avpCode;
	private String avpName;
	private String avpType;

	private String xmlTag;

	public ConvMapInfo() {
	}

	public ConvMapInfo(String serviceCtxID, int avpCode, String avpName,
			String avpType, int venderID, String xmlTag, String xmlType) {
		this.serviceCtxID = serviceCtxID;
		this.avpCode = avpCode;
		this.avpName = avpName;
		this.avpType = avpType;
		this.venderID = venderID;
		this.xmlTag = xmlTag;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getVenderID() {
		return venderID;
	}

	public void setVenderID(int venderID) {
		this.venderID = venderID;
	}

	public String getServiceCtxID() {
		return serviceCtxID;
	}

	public void setServiceCtxID(String serviceCtxID) {
		this.serviceCtxID = serviceCtxID;
	}

	public int getAvpCode() {
		return avpCode;
	}

	public void setAvpCode(int avpCode) {
		this.avpCode = avpCode;
	}

	public String getAvpName() {
		return avpName;
	}

	public void setAvpName(String avpName) {
		this.avpName = avpName;
	}

	public String getAvpType() {
		return avpType;
	}

	public void setAvpType(String avpType) {
		this.avpType = avpType;
	}

	public String getXmlTag() {
		return xmlTag;
	}

	public void setXmlTag(String xmlTag) {
		this.xmlTag = xmlTag;
	}

	@Transient
	public int getTypeCode() {
		if ("Integer32".equalsIgnoreCase(avpType)) {
			return AVP_INT32;
		} else if ("Integer64".equalsIgnoreCase(avpType)) {
			return AVP_INT64;
		} else if ("Unsigned32".equalsIgnoreCase(avpType)) {
			return AVP_U32;
		} else if ("Unsigned64".equalsIgnoreCase(avpType)) {
			return AVP_U64;
		} else if ("UTF8String".equalsIgnoreCase(avpType)) {
			return AVP_UTF8String;
		} else if ("OctetString".equalsIgnoreCase(avpType)) {
			return AVP_OctetString;
		} else if ("Grouped".equalsIgnoreCase(avpType)) {
			return AVP_Grouped;
		} else if ("Address".equalsIgnoreCase(avpType)) {
			return AVP_Address;
		} else if ("Time".equalsIgnoreCase(avpType)) {
			return AVP_Time;
		} else if ("Enumerated".equalsIgnoreCase(avpType)) {
			return AVP_Enumerated;
		} else if ("IPFilterRule".equalsIgnoreCase(avpType)) {
			return AVP_OctetString;
		} else if ("DiameterIdentity".equalsIgnoreCase(avpType)) {
			return AVP_OctetString;
		} else if ("Any".equalsIgnoreCase(avpType)) {
			return AVP_OctetString;
		} else {
			throw new RuntimeException("bad avptype " + avpType);
		}
	}

	@Override
	public String toString() {
		return "ConvMapInfo [serviceCtxID=" + serviceCtxID + ", venderID=" + venderID + ", avpCode=" + avpCode + ", avpName=" + avpName + ", avpType=" + avpType + ", xmlTag=" + xmlTag + "]\r\n";
	}
}
